<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>xeokit Example</title>
    <link href="../css/pageStyle.css" rel="stylesheet"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script>
</head>
<body>
<input type="checkbox" id="info-button"/>
<label for="info-button" class="info-button"><i class="far fa-3x fa-question-circle"></i></label>
<canvas id="myCanvas"></canvas>
<div class="slideout-sidebar">
    <img class="info-icon" src="../../assets/images/geolocation_icon.png"/>
    <h1>WebIFCLoaderPlugin</h1>
    <p>Loading an IFC model and positioning it at Cartesian coordinates [18201100000000.79, 9.91, -51729900000000.84]
        within the Viewer's World-space coordinate system.</p>
    <p>Note that the technique demonstrated here also works with all the other xeokit loader plugins, including <a
            href="../../docs/class/src/plugins/XKTLoaderPlugin/XKTLoaderPlugin.js~XKTLoaderPlugin.html"
            target="_other">XKTLoaderPlugin</a>.</p>
    <h3>Stats</h3>
    <ul>
        <li>
            <div id="time">Loading JavaScript modules...</div>
        </li>
    </ul>
    <h3>Components Used</h3>
    <ul>
        <li>
            <a href="../../docs/class/src/viewer/Viewer.js~Viewer.html"
               target="_other">Viewer</a>
        </li>
        <li>
            <a href="../../docs/class/src/plugins/WebIFCLoaderPlugin/WebIFCLoaderPlugin.js~WebIFCLoaderPlugin.html"
               target="_other">WebIFCLoaderPlugin</a>
        </li>
    </ul>
    <h3>Assets</h3>
    <ul>
        <li>
            <a href="http://openifcmodel.cs.auckland.ac.nz/Model/Details/274"
               target="_other">Model source</a>
        </li>
    </ul>
</div>
</body>
<script type="module">

    import {Viewer, WebIFCLoaderPlugin} from "../../dist/xeokit-sdk.min.es.js";
    import * as WebIFC from "https://cdn.jsdelivr.net/npm/web-ifc@0.0.51/web-ifc-api.js";

    const viewer = new Viewer({
        canvasId: "myCanvas",
        transparent: true
    });

    const IfcAPI = new WebIFC.IfcAPI();

    IfcAPI.SetWasmPath("https://cdn.jsdelivr.net/npm/web-ifc@0.0.51/");

    IfcAPI.Init().then(() => {

        const webIFCLoader = new WebIFCLoaderPlugin(viewer, {
            WebIFC,
            IfcAPI
        });

        const sceneModel = webIFCLoader.load({
            id: "myModel",
            src: "../../assets/models/ifc/Duplex.ifc",
            position: [18201100000000.79, 9.91, -51729900000000.84]
        });

        const t0 = performance.now();

        document.getElementById("time").innerHTML = "Loading model...";

        sceneModel.on("loaded", () => {

            const t1 = performance.now();

            document.getElementById("time").innerHTML = `Model loaded in ${Math.floor(t1 - t0) / 1000.0} seconds<br>Objects: ${sceneModel.numEntities}`;

            viewer.cameraFlight.jumpTo(sceneModel);
        });
    });

    window.viewer = viewer;
</script>
</html>